"""
Browser displays the mail as html
Written By: Daniel Ortiz
"""
import wx.webkit as webkit
import wx
import sys

class MailBrowser(webkit.WebKitCtrl):
    def __init__(self, parent):
        self.parent = parent
        webkit.WebKitCtrl.__init__(self, parent)
        self.InitialState()
        self.Variables()
        self.BindEvents()
    
    def InitialState(self):
        """Set the state of the browser"""
        self.MakeEditable(False)
    
    def Variables(self):
        """Initiate class-wide variables"""
        self.resize = False
        self.body = ''
    
    def BindEvents(self):
        """Bind the class wide events"""
        self.Bind(wx.EVT_SIZE, self.OnSize)
        self.Bind(wx.EVT_IDLE, self.OnIdle)
        
    def OnSize(self, event):
        """Resize the window"""
        self.resize = True
        event.Skip()
        
    def OnIdle(self, event):
        """Resize the window when idle"""
        if self.resize:
            self.resize = False
            
    def Add(self, body):
        """Add the source to the browser"""
        self.body = body
        self.SetPageSource(body, '')
        
    def AsHTML(self):
        """Return the body of the data as html"""
        return self.body
        
    def GetData(self):
        """Return the data in the source"""
        return self.body
    
    def ReloadMail(self):
        """Reload the base mail"""
        self.SetPageSource(self.body)
            
